package servlets;

import beans.Person_Beans;
import beans.Person_Logic_Beans;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import javax.swing.*;
import java.io.IOException;
import java.util.List;

//register 页面 servlet

@WebServlet(name = "person",urlPatterns = "/person")
public class Person_Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String NAME = req.getParameter("NAME");
        String IDTYPE = req.getParameter("IDTYPE");
        String IDNUMBER = req.getParameter("IDNUMBER");
        double BASENUMBER = Double.parseDouble(req.getParameter("BASENUMBER"));

        //数据 Beans
        Person_Beans person_beans = new Person_Beans();
        person_beans.setNAME(NAME);
        person_beans.setBASENUMBER(BASENUMBER);
        person_beans.setIDTYPE(IDTYPE);
        person_beans.setIDNUMBER(IDNUMBER);

        //逻辑 Beans
        Person_Logic_Beans person_logic_beans = new Person_Logic_Beans();
        //1.判断账户是否存在
        List<Person_Beans> list = person_logic_beans.Check_Person_Idname(person_beans);
        if (list.isEmpty()){
            JOptionPane.showMessageDialog(null, "个人不存在，请重新输入，或查看是否入职！");
            resp.sendRedirect("register.jsp");
        }
        else {
            if (person_logic_beans.Check_Person_Peraccstate(list)){

            }
            else{
                JOptionPane.showMessageDialog(null, "您已开户！");
            }
        }

    }
}
